//package com.plian.system.service.im.impl;
//
//import cn.hutool.core.util.StrUtil;
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.baomidou.mybatisplus.core.toolkit.Wrappers;
//import com.plian.Tools.BigDecimalUtil;
//import com.plian.Tools.CollectionUtil;
//import com.plian.Tools.DateUtil;
//import com.plian.system.dto.im.InvestmentReportDTO;
//import com.plian.system.dto.im.ProjectReportDTO;
//import com.plian.system.entity.fr.enterprise.Enterprise;
//import com.plian.system.entity.im.*;
//import com.plian.system.entity.sys.Dict;
//import com.plian.system.entity.sys.Org;
//import com.plian.system.properties.GzwProperties;
//import com.plian.system.service.fr.enterprise.IEnterpriseService;
//import com.plian.system.service.im.*;
//import com.plian.system.service.sys.dict.IDictService;
//import com.plian.system.service.sys.orgzation.IOrgService;
//import com.plian.system.vo.im.InvestmentReportVO;
//import com.plian.system.vo.im.ProjectReportVO;
//import com.plian.system.vo.report.*;
//import com.plian.system.wrapper.im.ProjectInfoWrapper;
//import lombok.AllArgsConstructor;
//import org.springframework.stereotype.Service;
//
//import java.math.BigDecimal;
//import java.math.RoundingMode;
//import java.util.*;
//import java.util.stream.Collectors;
//
///**
// * @Author: Take-off
// * @Description: TODO
// * @Date: 2023/2/9 10:58 AM
// * @Version: 1.0
// **/
//@Service
//@AllArgsConstructor
//public class InvestmentReportServiceImpl implements IInvestmentReportService {
//
//    private final GzwProperties gzwProperties;
//
//    private final IProjectInfoService projectInfoService;
//
//    private final ProjectInfoWrapper projectInfoWrapper;
//
//    private final IFixedInvestmentPlanService fixedInvestmentPlanService;
//
//    private final IStakeInvestmentPlanService stakeInvestmentPlanService;
//
//    private final IBaseInvestmentExecutionService baseInvestmentExecutionService;
//
//    private final IEffectiveInvestmentService effectiveInvestmentService;
//
//    private final IExecutionProjectSituationService projectSituationService;
//
//    private final IOrgService orgService;
//
//    private final IEnterpriseService enterpriseService;
//
//    private final IDictService dictService;
//
//    @Override
//    public ReportReturnVO getProjectReport(ProjectReportDTO dto){
//        List<ProjectReportVO> projectReportVOS = new ArrayList<>();
//
//        Date start = DateUtil.parse(dto.getYears(), DateUtil.PATTERN_MONTH);
//        Date date = DateUtil.plusMonths(start, 1);
//        List<Integer> investmentCategories = dto.getInvestmentCategories();
//        List<Integer> projectStatuses = dto.getProjectStatuses();
//        //获取项目库信息
//        LambdaQueryWrapper<ProjectInfo> wrapper = Wrappers.<ProjectInfo>lambdaQuery().le(ProjectInfo::getCreateTime, date);
//        if (CollectionUtil.isNotEmpty(investmentCategories)){
//            if (investmentCategories.contains(1)){
//                wrapper.eq(ProjectInfo::getInvestmentCategory,1);
//            }else if (investmentCategories.contains(2)){
//                wrapper.eq(ProjectInfo::getInvestmentCategory,2);
//            }else if (investmentCategories.contains(3)){
//                //重点项目
//                wrapper.eq(ProjectInfo::getIsImportant,2);
//            }
//        }else {
//            wrapper.isNull(ProjectInfo::getInvestmentCategory).eq(ProjectInfo::getIsImportant,1);
//        }
//        if (CollectionUtil.isNotEmpty(projectStatuses)){
//            if (investmentCategories.contains(1)){
//                wrapper.eq(ProjectInfo::getProjectStatus,1);
//            }else if (investmentCategories.contains(2)){
//                wrapper.eq(ProjectInfo::getProjectStatus,2);
//            }else if (investmentCategories.contains(3)){
//                //计划完工
//                wrapper.between(ProjectInfo::getPlanFinishDate,start,date);
//            }
//        }else {
//            wrapper.eq(ProjectInfo::getProjectStatus,3);
//        }
//        //项目库
//        List<ProjectInfo> projectInfos = projectInfoService.list(wrapper);
//        //投资执行
//        if (CollectionUtil.isNotEmpty(projectInfos)){
//            //企业简称
//            List<Enterprise> enterprises = enterpriseService.list();
//            //字典
//            List<Dict> dicts = dictService.list();
//            Map<Integer, List<ProjectInfo>> mapByStatus = projectInfos.stream().collect(Collectors.groupingBy(ProjectInfo::getProjectStatus));
//            Set<Integer> projectStatus = mapByStatus.keySet();
//            int i = 1;
//            //投资执行
//            List<BaseInvestmentExecution> baseInvestmentExecutions = baseInvestmentExecutionService.list();
//            List<Long> baseIds = baseInvestmentExecutions.stream().filter(m -> dto.getYears().equals(m.getFilingMonth())).map(BaseInvestmentExecution::getId).collect(Collectors.toList());
//            List<EffectiveInvestment> effectiveInvestments = new ArrayList<>();
//            List<Long> effectiveIds = new ArrayList<>();
//            if (CollectionUtil.isNotEmpty(baseIds)){
//                effectiveInvestments  = effectiveInvestmentService.list(Wrappers.<EffectiveInvestment>lambdaQuery().in(EffectiveInvestment::getBaseInvestmentExecutionId, baseIds));
//                if (CollectionUtil.isNotEmpty(effectiveInvestments)){
//                    effectiveIds = effectiveInvestments.stream().map(EffectiveInvestment::getId).collect(Collectors.toList());;
//                }
//            }
//            List<Long> projectIds = projectInfos.stream().map(ProjectInfo::getId).collect(Collectors.toList());
//            List<ExecutionProjectSituation> executionProjectSituations = projectSituationService.list(Wrappers.<ExecutionProjectSituation>lambdaQuery().in(ExecutionProjectSituation::getProjectId, projectIds));
//            if (projectStatus.contains(1)){
//                //续建
//                List<ProjectInfo> infoList = mapByStatus.get(1);
//                projectReportVOS.add(ProjectReportVO.builder().serialNumber("续建项目（" +infoList.size() + "个）" ).build());
//                //根据组织id group
//                addReportVO(infoList, i,
//                            baseInvestmentExecutions, executionProjectSituations,  effectiveInvestments,effectiveIds,
//                            projectReportVOS,enterprises,dicts);
//
//
//            }
//            if (projectStatus.contains(2)){
//                //续建
//                List<ProjectInfo> infoList = mapByStatus.get(2);
//                projectReportVOS.add(ProjectReportVO.builder().serialNumber("新建项目（" +infoList.size() + "个）" ).build());
//                //根据组织id group
//                Map<String, List<ProjectInfo>> mapByOrg = infoList.stream().filter(m -> Optional.ofNullable(m.getFillingUnitId()).isPresent()).collect(Collectors.groupingBy(ProjectInfo::getFillingUnitId));
//                //根据组织id group
//                addReportVO(infoList, i,
//                        baseInvestmentExecutions, executionProjectSituations,  effectiveInvestments,effectiveIds,
//                        projectReportVOS,enterprises,dicts);
//            }
//        }
//        ReportReturnVO reportReturnVO = new ReportReturnVO();
//        ReportVO reportVO = new ReportVO();
//
//        List<HeaderVO> headerVOS = new ArrayList<>();
//        headerVOS.add(HeaderVO.builder().key("anticipateTime").title("计划开工").build());
//        headerVOS.add(HeaderVO.builder().key("actualTime").title("实际开工").build());
//
//        reportVO
//                .addHeader(HeaderVO.builder().key("serialNumber").title("序号").build())
//                .addHeader(HeaderVO.builder().key("companyName").title("企业名称").build())
//                .addHeader(HeaderVO.builder().key("projectName").title("项目名称").build())
//                .addHeader(HeaderVO.builder().key("projectNature").title("项目类别").build())
//                .addHeader(HeaderVO.builder().key("plannedInvestment").title("年度计划").build())
//                .addHeader(HeaderVO.builder().children(headerVOS).title("开工时间").build())
//                .addHeader(HeaderVO.builder().key("allCompleteInvestment").title("累计投资").build())
//                .addHeader(HeaderVO.builder().key("mainProgress").title("形象进度").build())
//                .addHeader(HeaderVO.builder().key("completionRate").title("完成率").build())
//        ;
//
//        reportVO.setData(projectReportVOS);
//        reportReturnVO.setGrids(reportVO);
//        return reportReturnVO;
//    }
//
//    /**
//     * @Description:  生成报表与小计
//     * @Author: Take-off
//     * @Date: 11:23 AM 2023/7/17
//     * @Param: [orgInfoVOS, i, baseInvestmentExecutions, executionProjectSituations, effectiveInvestments, effectiveIds, projectReportVOS]
//     * @return: void
//     **/
//    private void addReportVO(List<ProjectInfo> infoList,int i,List<BaseInvestmentExecution> baseInvestmentExecutions,
//                             List<ExecutionProjectSituation> executionProjectSituations, List<EffectiveInvestment> effectiveInvestments
//    ,List<Long> effectiveIds,List<ProjectReportVO> projectReportVOS,List<Enterprise> enterprises,List<Dict> dicts){
//        Map<String, List<ProjectInfo>> mapByOrg = infoList.stream().filter(m -> Optional.ofNullable(m.getCreateCompanyId()).isPresent()).collect(Collectors.groupingBy(ProjectInfo::getCreateCompanyId));
//        for (String orgId:mapByOrg.keySet()){
//            List<ProjectReportVO> subtotalList = new ArrayList<>();
//            List<ProjectInfo> orgInfos = mapByOrg.get(orgId);
//            //简称
//            String orgName = "";
//            Optional<Enterprise> enterpriseOptional = enterprises.stream().filter(m -> orgId.equals(m.getOrgId())).findFirst();
//            if (enterpriseOptional.isPresent()){
//                Enterprise enterprise = enterpriseOptional.get();
//                if (StrUtil.isNotBlank(enterprise.getUnitCheck())){
//                    orgName = enterprise.getUnitCheck();
//                }else {
//                    orgName = orgService.getById(orgId).getName();
//                }
//            }else {
//                orgName = orgService.getById(orgId).getName();
//            }
//            for (ProjectInfo projectInfo:orgInfos){
//                //项目基础信息
//                ProjectReportVO reportVO = getReportVO(projectInfo, i, orgName,dicts);
//                //实际投放时间
//                Optional<ExecutionProjectSituation> minExe = executionProjectSituations.stream().filter(m -> projectInfo.getId().equals(m.getProjectId()) && Optional.ofNullable(m.getCompleteInvestment()).isPresent() && m.getCompleteInvestment().compareTo(BigDecimal.ZERO) > 0)
//                        .min(Comparator.comparing(ExecutionProjectSituation::getCreateTime));
//                if (minExe.isPresent()){
//                    ExecutionProjectSituation situation = minExe.get();
//                    effectiveInvestments.stream().filter(m -> situation.getEffectiveInvestmentId().equals(m.getId())).findFirst().flatMap(effect ->
//                            baseInvestmentExecutions.stream().filter(m -> effect.getBaseInvestmentExecutionId().equals(m.getId())).findFirst()).ifPresent(base -> {
//                        reportVO.setActualTime(base.getFilingMonth());
//                    });
//                }
//                //当月投资执行
//                if (CollectionUtil.isNotEmpty(effectiveIds)){
//                    List<Long> effectiveIdList = effectiveIds;
//                    Optional<ExecutionProjectSituation> situationOptional = executionProjectSituations.stream().filter(m -> projectInfo.getId().equals(m.getProjectId()) && effectiveIdList.contains(m.getEffectiveInvestmentId())).findFirst();
//                    if (situationOptional.isPresent()){
//                        ExecutionProjectSituation situation = situationOptional.get();
//                        reportVO.setPlannedInvestment(situation.getPlanTotalInvestment());
//                        BigDecimal lastCompleteInvestment = situation.getLastCompleteInvestment() != null ? situation.getLastCompleteInvestment() : BigDecimal.ZERO;
//                        BigDecimal completeInvestment = situation.getCompleteInvestment() != null ? situation.getCompleteInvestment() : BigDecimal.ZERO;
//                        BigDecimal allCompleteInvestment = lastCompleteInvestment.add(completeInvestment);
//                        reportVO.setAllCompleteInvestment(allCompleteInvestment);
//                        reportVO.setMainProgress(situation.getMainProgress());
//                        effectiveInvestments.stream().filter(m -> situation.getEffectiveInvestmentId().equals(m.getId())).findFirst().ifPresent(effect ->{
//                            Optional.ofNullable(effect.getPlanEffectiveInvestment()).ifPresent(plan ->{
//                                BigDecimal completionRate = (allCompleteInvestment.multiply(new BigDecimal("100"))).divide(plan, 2, RoundingMode.HALF_UP);
//                                reportVO.setCompletionRate(completionRate);
//                            });
//                        });
//                    }
//                }
//                if (Optional.ofNullable(reportVO.getPlannedInvestment()).isPresent() || Optional.ofNullable(reportVO.getAllCompleteInvestment()).isPresent()){
//                    subtotalList.add(reportVO);
//                    i++;
//                }
//            }
//            if (CollectionUtil.isNotEmpty(subtotalList)){
//                ProjectReportVO subtotal = getSubtotal(subtotalList);
//                projectReportVOS.addAll(subtotalList);
//                projectReportVOS.add(subtotal);
//            }
//        }
//    }
//
//    /**
//     * @Description:  生成小计
//     * @Author: Take-off
//     * @Date: 11:19 AM 2023/7/17
//     * @Param: [subtotalList]
//     * @return: com.plian.system.vo.im.ProjectReportVO
//     **/
//    public ProjectReportVO getSubtotal(List<ProjectReportVO> subtotalList){
//        BigDecimal plannedInvestment = subtotalList.stream().map(ProjectReportVO::getPlannedInvestment).filter(m -> Optional.ofNullable(m).isPresent()).reduce(BigDecimal.ZERO, BigDecimal::add);
//        BigDecimal allCompleteInvestment = subtotalList.stream().map(ProjectReportVO::getAllCompleteInvestment).filter(m -> Optional.ofNullable(m).isPresent()).reduce(BigDecimal.ZERO, BigDecimal::add);
//        List<ProjectReportVO> reportVOList = subtotalList.stream().filter(m -> Optional.ofNullable(m.getCompletionRate()).isPresent()).collect(Collectors.toList());
//        BigDecimal completionRate = BigDecimal.ZERO;
//        if (CollectionUtil.isNotEmpty(reportVOList)){
//            BigDecimal allRate = reportVOList.stream().map(ProjectReportVO::getCompletionRate).reduce(BigDecimal.ZERO, BigDecimal::add);
//            completionRate = allRate.divide(new BigDecimal(reportVOList.size()),2,BigDecimal.ROUND_HALF_UP);
//        }
//        return ProjectReportVO.builder().serialNumber("小计").plannedInvestment(plannedInvestment).allCompleteInvestment(allCompleteInvestment).completionRate(completionRate).build();
//    }
//
//    /**
//     * @Description: //TODO 项目信息生成报表信息
//     * @Author: Take-off
//     * @Date: 11:13 AM 2023/7/17
//     * @Param: [projectInfoVO, i]
//     * @return: com.plian.system.vo.im.ProjectReportVO
//     **/
//    public ProjectReportVO getReportVO(ProjectInfo projectInfo,int i,String orgName, List<Dict> dicts){
//        ProjectReportVO projectReportVO = new ProjectReportVO();
//        projectReportVO.setSerialNumber(i +"");
//        projectReportVO.setCompanyName(orgName);
//        projectReportVO.setProjectName(projectInfo.getProjectName());
//        Optional.ofNullable(projectInfo.getProjectNatureId()).flatMap(natureId ->
//                dicts.stream().filter(m -> natureId.equals(m.getCode())).findFirst()).ifPresent(dict -> {
//                    projectReportVO.setProjectNature(dict.getName());
//        });
//        Optional.ofNullable(projectInfo.getAnticipateStartTime()).ifPresent(date ->{
//            projectReportVO.setAnticipateTime(DateUtil.format(date,DateUtil.PATTERN_MONTH));
//        });
//        return projectReportVO;
//
//    }
//
//    @Override
//    public InvestmentReportVO getOverview(InvestmentReportDTO dto){
//        InvestmentReportVO reportVO = new InvestmentReportVO();
//
//        Date nextYear = DateUtil.plusYears(DateUtil.parse(dto.getYear(), DateUtil.PATTERN_YEAR), 1);
//        //项目信息
//        List<ProjectInfo> projectInfos = new ArrayList<>();
//        if (dto.getOrgId().equals(gzwProperties.getId()) || dto.getOrgId().equals(gzwProperties.getReportId())) {
//            //国资委
//            projectInfos = projectInfoService.list(new LambdaQueryWrapper<ProjectInfo>().le(ProjectInfo::getCreateTime, nextYear));
//        }else {
//            //集团
//            projectInfos = projectInfoService.list(new LambdaQueryWrapper<ProjectInfo>().le(ProjectInfo::getCreateTime, nextYear).eq(ProjectInfo::getCreateCompanyId,dto.getOrgId()));
//        }
//        //总计划投资
//        BigDecimal planInvestmentAmount = BigDecimal.ZERO;
//        if (CollectionUtil.isNotEmpty(projectInfos)){
//            reportVO.setItemTotal(projectInfos.size());
//            List<Long> projectIds = projectInfos.stream().map(ProjectInfo::getId).filter(m -> Optional.ofNullable(m).isPresent()).collect(Collectors.toList());
//            //固定
//            List<FixedInvestmentPlan> fixedInvestmentPlans = fixedInvestmentPlanService.list(new LambdaQueryWrapper<FixedInvestmentPlan>().in(FixedInvestmentPlan::getProjectId, projectIds));
//            //股权
//            List<StakeInvestmentPlan> stakeInvestmentPlans = stakeInvestmentPlanService.list(new LambdaQueryWrapper<StakeInvestmentPlan>().in(StakeInvestmentPlan::getProjectId, projectIds));
//            //求和
//            planInvestmentAmount = planInvestmentAmount.add(addFixedAmount(fixedInvestmentPlans)).add(addStakeAmount(stakeInvestmentPlans));
//        }
//        reportVO.setPlanInvestmentAmount(planInvestmentAmount);
//
//        //累积完成投资
//        List<BaseInvestmentExecution> investmentExecutions = new ArrayList<>();
//        if (dto.getOrgId().equals(gzwProperties.getId()) || dto.getOrgId().equals(gzwProperties.getReportId())) {
//            //国资委
//            investmentExecutions = baseInvestmentExecutionService.list(new LambdaQueryWrapper<BaseInvestmentExecution>().like(BaseInvestmentExecution::getFilingMonth, dto.getYear()));
//        }else {
//            //集团
//            investmentExecutions = baseInvestmentExecutionService.list(new LambdaQueryWrapper<BaseInvestmentExecution>().like(BaseInvestmentExecution::getFilingMonth, dto.getYear()).eq(BaseInvestmentExecution::getFilingUnitId,dto.getOrgId()));
//        }
//        List<EffectiveInvestment> effectiveInvestments = getExecutions(investmentExecutions);
//        BigDecimal finishInvestmentAmount = addEffectiveDecimal(effectiveInvestments);
//        reportVO.setFinishInvestmentAmount(finishInvestmentAmount);
//
//        //投资计划完成率
//        BigDecimal planInvestmentRate = BigDecimal.ZERO;
//        if ( (planInvestmentAmount.compareTo(BigDecimal.ZERO) >0 ) && (finishInvestmentAmount.compareTo(BigDecimal.ZERO) >0) ){
//            planInvestmentRate = finishInvestmentAmount.multiply(new BigDecimal(100)).divide(finishInvestmentAmount,2, RoundingMode.HALF_UP);
//        }
//        reportVO.setPlanInvestmentRate(planInvestmentRate);
//
//        //重点项目
//        List<ExecutionProjectSituation> situations = getSituations(effectiveInvestments);
//        List<ProjectInfo> majorProjects = getMajorProjects(situations, projectInfos);
//        if (CollectionUtil.isNotEmpty(majorProjects)){
//            reportVO.setKeyItemTotal(majorProjects.size());
//        }
//        //重点项目-总计划投资
//        BigDecimal keyPlanAmount = BigDecimal.ZERO;
//        //重点项目-累计完成投资金额
//        BigDecimal keyFinishAmount = BigDecimal.ZERO;
//        if (CollectionUtil.isNotEmpty(situations)){
//            List<BigDecimal> bigDecimals = situations.stream().map(ExecutionProjectSituation::getPlanTotalInvestment).filter(m -> Optional.ofNullable(m).isPresent()).collect(Collectors.toList());
//            keyPlanAmount = BigDecimalUtil.addBigDecimals(bigDecimals);
//
//            List<BigDecimal> decimals = situations.stream().map(ExecutionProjectSituation::getLastCompleteInvestment).filter(m -> Optional.ofNullable(m).isPresent()).collect(Collectors.toList());
//            keyFinishAmount = BigDecimalUtil.addBigDecimals(decimals);
//        }
//        reportVO.setKeyPlanAmount(keyPlanAmount);
//        reportVO.setKeyFinishAmount(keyFinishAmount);
//
//        //重点项目-计划完成率
//        BigDecimal keyPlanRate = BigDecimal.ZERO;
//        if ( (keyPlanAmount.compareTo(BigDecimal.ZERO) >0 ) && (keyFinishAmount.compareTo(BigDecimal.ZERO) >0) ){
//            keyPlanRate = keyFinishAmount.multiply(new BigDecimal(100)).divide(keyPlanAmount,2, RoundingMode.HALF_UP);
//        }
//        reportVO.setKeyPlanRate(keyPlanRate);
//
//        return reportVO;
//    }
//
//    @Override
//    public ChartsVO getExecutionAmount(InvestmentReportDTO dto){
//        ChartsVO chartsVO = new ChartsVO();
//        //y轴
//        List<XAxisVO> xAxisVOList = new ArrayList<>();
//        XAxisVO xAxisVO = new XAxisVO();
//        List<String> xAxisVOData = new ArrayList<>();
//        xAxisVO.setData(xAxisVOData);
//        xAxisVOList.add(xAxisVO);
//        chartsVO.setXAxis(xAxisVOList);
//        //值
//        List<SeriesVO> seriesVOList = new ArrayList<>();
//        chartsVO.setSeries(seriesVOList);
//        SeriesVO planAmount = SeriesVO.builder().name("计划投资金额").type("bar").build();
//        SeriesVO finishAmount = SeriesVO.builder().name("完成投资金额").type("bar").build();
//        List<Object> planAmountData = new ArrayList<>();
//        List<Object> finishAmountData = new ArrayList<>();
//        planAmount.setData(planAmountData);
//        finishAmount.setData(finishAmountData);
//        seriesVOList.add(planAmount);
//        seriesVOList.add(finishAmount);
//
//        //项目投资执行
//        List<BaseInvestmentExecution> investmentExecutions = new ArrayList<>();
//
//        //横坐标
//        List<Org> orgList = new ArrayList<>();
//        if (dto.getOrgId().equals(gzwProperties.getId()) || dto.getOrgId().equals(gzwProperties.getReportId())) {
//            //13家
//            orgList = orgService.directlyUnderUnitNoChild(false).getList();
//            //国资委
//            investmentExecutions = baseInvestmentExecutionService.list(new LambdaQueryWrapper<BaseInvestmentExecution>().like(BaseInvestmentExecution::getFilingMonth, dto.getYear()));
//        }else {
//            orgList.add(orgService.getById(dto.getOrgId()));
//            //集团
//            investmentExecutions = baseInvestmentExecutionService.list(new LambdaQueryWrapper<BaseInvestmentExecution>().like(BaseInvestmentExecution::getFilingMonth, dto.getYear()).eq(BaseInvestmentExecution::getFilingUnitId,dto.getOrgId()));
//        }
//        //简称
//        List<Enterprise> unitCheckNames = new ArrayList<>();
//        try {
//            unitCheckNames = enterpriseService.getAllUnitCheckName();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//
//        if (CollectionUtil.isNotEmpty(investmentExecutions)){
//            //查询有效投资
//            List<EffectiveInvestment> effectiveInvestments = getExecutions(investmentExecutions);
//            if (CollectionUtil.isNotEmpty(effectiveInvestments)){
//                List<Long> effectIds = effectiveInvestments.stream().map(EffectiveInvestment::getId).collect(Collectors.toList());
//                //项目投资情况
//                List<ExecutionProjectSituation> projectSituations = projectSituationService.list(new LambdaQueryWrapper<ExecutionProjectSituation>().in(ExecutionProjectSituation::getEffectiveInvestmentId, effectIds));
//                for (Org org:orgList){
//                    //计划金额
//                    BigDecimal planInvestmentAmount = BigDecimal.ZERO;
//                    //完成金额
//                    BigDecimal finishInvestmentAmount = BigDecimal.ZERO;
//
//                    String orgId = org.getId();
//                    //X轴，简称
//                    List<Enterprise> unitDatas = unitCheckNames.stream().filter(m -> Optional.ofNullable(m.getOrgId()).isPresent() && orgId.equals(m.getOrgId())).collect(Collectors.toList());
//                    if (CollectionUtil.isNotEmpty(unitDatas)){
//                        xAxisVOData.add(unitDatas.get(0).getUnitCheck());
//                    }
//                    //当前企业最新的主表
//                    List<BaseInvestmentExecution> baseExecutions = investmentExecutions.stream().filter(m -> orgId.equals(m.getFilingUnitId())).sorted(Comparator.comparing(BaseInvestmentExecution::getFilingMonth).reversed()).collect(Collectors.toList());
//                    if (CollectionUtil.isNotEmpty(baseExecutions)){
//                        //有效投资
//                        List<EffectiveInvestment> investments = effectiveInvestments.stream().filter(m -> baseExecutions.get(0).getId().equals(m.getBaseInvestmentExecutionId())).collect(Collectors.toList());
//                        //项目类型
//                        if (CollectionUtil.isNotEmpty(investments)){
//                            EffectiveInvestment investment = investments.get(0);
//                            //项目投资情况
//                            List<ExecutionProjectSituation> situationList = new ArrayList<>();
//                            if (dto.getType() == 1){
//                                //全部
//                                situationList = projectSituations.stream().filter(m -> investment.getId().equals(m.getEffectiveInvestmentId())).collect(Collectors.toList());
//                            }else if (dto.getType() == 2){
//                                //重点项目
//                                situationList = projectSituations.stream()
//                                        .filter(m -> investment.getId().equals(m.getEffectiveInvestmentId()) && (Optional.ofNullable(m.getIsMain()).isPresent() && m.getIsMain() == 2)).collect(Collectors.toList());
//                            }
//                            //计算
//                            if (CollectionUtil.isNotEmpty(situationList)){
//                                List<BigDecimal> plans = situationList.stream().map(ExecutionProjectSituation::getPlanTotalInvestment).filter(m -> Optional.ofNullable(m).isPresent()).collect(Collectors.toList());
//                                planInvestmentAmount = BigDecimalUtil.addBigDecimals(plans);
//
//                                List<BigDecimal> finishs = situationList.stream().map(ExecutionProjectSituation::getLastCompleteInvestment).filter(m -> Optional.ofNullable(m).isPresent()).collect(Collectors.toList());
//                                finishInvestmentAmount = BigDecimalUtil.addBigDecimals(finishs);
//                            }
//                        }
//                    }
//                    planAmountData.add(planInvestmentAmount);
//                    finishAmountData.add(finishInvestmentAmount);
//                }
//            }
//        }
//
//        return chartsVO;
//    }
//
//
//    @Override
//    public PieChartVO getExecutionPie(InvestmentReportDTO dto){
//        PieChartVO pieChartVO = new PieChartVO();
//        List<PieValueVO> pieValueVOS = new ArrayList<>();
//        pieChartVO.setData(pieValueVOS);
//
//        //执行主表
//        List<BaseInvestmentExecution> investmentExecutions = new ArrayList<>();
//        if (dto.getOrgId().equals(gzwProperties.getId()) || dto.getOrgId().equals(gzwProperties.getReportId())) {
//            //国资委
//            investmentExecutions = baseInvestmentExecutionService.list(new LambdaQueryWrapper<BaseInvestmentExecution>().like(BaseInvestmentExecution::getFilingMonth, dto.getYear()));
//        }else {
//            //集团
//            investmentExecutions = baseInvestmentExecutionService.list(new LambdaQueryWrapper<BaseInvestmentExecution>().like(BaseInvestmentExecution::getFilingMonth, dto.getYear()).eq(BaseInvestmentExecution::getFilingUnitId,dto.getOrgId()));
//        }
//        List<EffectiveInvestment> effectiveInvestments = getExecutions(investmentExecutions);
//        if (CollectionUtil.isNotEmpty(effectiveInvestments)){
//            List<Long> effectIds = effectiveInvestments.stream().map(EffectiveInvestment::getId).collect(Collectors.toList());
//            List<ExecutionProjectSituation> majorSituations= projectSituationService.list(new LambdaQueryWrapper<ExecutionProjectSituation>().in(ExecutionProjectSituation::getEffectiveInvestmentId, effectIds));
//            //股权
//            List<BigDecimal> stakes = majorSituations.stream().filter(m -> Optional.ofNullable(m.getProjectType()).isPresent() && m.getProjectType() == 1).map(ExecutionProjectSituation::getLastCompleteInvestment).collect(Collectors.toList());
//            PieValueVO stake = PieValueVO.builder().name("股权类").value(BigDecimalUtil.addBigDecimals(stakes)).build();
//            //基金
//            List<BigDecimal> funds = majorSituations.stream().filter(m -> Optional.ofNullable(m.getProjectType()).isPresent() && m.getProjectType() == 1 && m.getIsFund() ==2).map(ExecutionProjectSituation::getLastCompleteInvestment).collect(Collectors.toList());
//            PieValueVO fund = PieValueVO.builder().name("其中;基金投资").value(BigDecimalUtil.addBigDecimals(funds)).build();
//            stake.setChild(Collections.singletonList(fund));
//            pieValueVOS.add(stake);
//            //固定资产
//            List<BigDecimal> fixeds = majorSituations.stream().filter(m -> Optional.ofNullable(m.getProjectType()).isPresent() && m.getProjectType() == 2).map(ExecutionProjectSituation::getLastCompleteInvestment).collect(Collectors.toList());
//            PieValueVO fix = PieValueVO.builder().name("固定资产类").value(BigDecimalUtil.addBigDecimals(fixeds)).build();
//            //重点项目
//            List<BigDecimal> mains = majorSituations.stream().filter(m -> Optional.ofNullable(m.getProjectType()).isPresent() && m.getProjectType() == 2 && m.getIsMain() ==2).map(ExecutionProjectSituation::getLastCompleteInvestment).collect(Collectors.toList());
//            PieValueVO main = PieValueVO.builder().name("其中;重点项目投资").value(BigDecimalUtil.addBigDecimals(mains)).build();
//            fix.setChild(Collections.singletonList(main));
//            pieValueVOS.add(fix);
//        }
//
//        return pieChartVO;
//    }
//
//    /**
//     * @Author: Take-off
//     * @Description: //TODO 获取重点项目
//     * @Date: 9:49 AM 2023/2/14
//     * @Param: [effectiveInvestments, projectInfos]
//     * @return: java.util.List<com.plian.system.entity.im.ProjectInfo>
//     **/
//    private List<ProjectInfo> getMajorProjects(List<ExecutionProjectSituation> majorSituations,List<ProjectInfo> projectInfos){
//        List<ProjectInfo> majorProjects = new ArrayList<>();
//        if (CollectionUtil.isNotEmpty(majorSituations)){
//            Set<Long> majorProjectIds = majorSituations.stream().map(ExecutionProjectSituation::getProjectId).filter(m -> Optional.ofNullable(m).isPresent()).collect(Collectors.toSet());
//            if (CollectionUtil.isNotEmpty(projectInfos)){
//                projectInfos.forEach(projectInfo -> {
//                    if (majorProjectIds.contains(projectInfo.getId())){
//                        majorProjects.add(projectInfo);
//                    }
//                });
//            }
//        }
//        return majorProjects;
//    }
//
//    /**
//     * @Author: Take-off
//     * @Description: //TODO 投资执行-重点项目情况
//     * @Date: 10:21 AM 2023/2/14
//     * @Param: [effectiveInvestments]
//     * @return: java.util.List<com.plian.system.entity.im.ExecutionProjectSituation>
//     **/
//    private List<ExecutionProjectSituation> getSituations(List<EffectiveInvestment> effectiveInvestments){
//        List<ExecutionProjectSituation> majorSituations = new ArrayList<>();
//        if (CollectionUtil.isNotEmpty(effectiveInvestments)){
//            List<Long> effectIds = effectiveInvestments.stream().map(EffectiveInvestment::getId).collect(Collectors.toList());
//            majorSituations= projectSituationService.list(new LambdaQueryWrapper<ExecutionProjectSituation>().in(ExecutionProjectSituation::getEffectiveInvestmentId, effectIds)
//                    .eq(ExecutionProjectSituation::getIsMain,2));
//        }
//        return majorSituations;
//    }
//
//    /**
//     * @Author: Take-off
//     * @Description: //TODO 累积完成投资金额
//     * @Date: 5:14 PM 2023/2/13
//     * @Param: [investmentExecutions]
//     * @return: java.util.List<com.plian.system.entity.im.BaseInvestmentExecution>
//     **/
//    private List<EffectiveInvestment> getExecutions(List<BaseInvestmentExecution> investmentExecutions){
//        List<BaseInvestmentExecution> investmentExecutionList = new ArrayList<>();
//        List<EffectiveInvestment> effectiveInvestments = new ArrayList<>();
//        if (CollectionUtil.isNotEmpty(investmentExecutions)){
//            Map<String, List<BaseInvestmentExecution>> executionByOrg = investmentExecutions.stream().filter(m -> Optional.ofNullable(m.getFilingUnitId()).isPresent()).collect(Collectors.groupingBy(BaseInvestmentExecution::getFilingUnitId));
//            Set<String> orgIds = executionByOrg.keySet();
//            for (String orgId:orgIds){
//                //当前企业的项目投资主表
//                List<BaseInvestmentExecution> executionList = executionByOrg.get(orgId);
//                BaseInvestmentExecution lastInvestment = getLastInvestment(executionList);
//                investmentExecutionList.add(lastInvestment);
//            }
//            if (CollectionUtil.isNotEmpty(investmentExecutionList)){
//                List<Long> executionIds = investmentExecutionList.stream().map(BaseInvestmentExecution::getId).collect(Collectors.toList());
//                //查询有效投资
//                effectiveInvestments = effectiveInvestmentService.list(new LambdaQueryWrapper<EffectiveInvestment>().in(EffectiveInvestment::getBaseInvestmentExecutionId, executionIds));
//            }
//        }
//        return effectiveInvestments;
//    }
//
//    /**
//     * @Author: Take-off
//     * @Description: //TODO 获取计算分数
//     * @Date: 9:36 AM 2023/2/14
//     * @Param: [effectiveInvestments]
//     * @return: java.math.BigDecimal
//     **/
//    private BigDecimal addEffectiveDecimal(List<EffectiveInvestment> effectiveInvestments){
//        BigDecimal bigDecimal = BigDecimal.ZERO;
//        if (CollectionUtil.isNotEmpty(effectiveInvestments)){
//            List<BigDecimal> decimals = effectiveInvestments.stream().map(EffectiveInvestment::getAllCompleteInvestment).filter(m -> Optional.ofNullable(m).isPresent()).collect(Collectors.toList());
//            bigDecimal = BigDecimalUtil.addBigDecimals(decimals);
//        }
//        return bigDecimal;
//    }
//
//    /**
//     * @Author: Take-off
//     * @Description: //TODO 找到最新的主表
//     * @Date: 4:44 PM 2023/2/13
//     * @Param: [executionList]
//     * @return: com.plian.system.entity.im.BaseInvestmentExecution
//     **/
//    private BaseInvestmentExecution getLastInvestment(List<BaseInvestmentExecution> executionList){
//        BaseInvestmentExecution baseInvestmentExecution = new BaseInvestmentExecution();
//        if (CollectionUtil.isNotEmpty(executionList)) {
//            //获取最新的一条
//            baseInvestmentExecution = executionList.stream().sorted(Comparator.comparing(BaseInvestmentExecution::getFilingMonth).reversed()).collect(Collectors.toList()).get(0);
//        }
//        return baseInvestmentExecution;
//    }
//
//    /**
//     * @Author: Take-off
//     * @Description:  固定-总计划投资
//     * @Date: 3:54 PM 2023/2/13
//     * @Param: [fixedInvestmentPlans]
//     * @return: java.math.BigDecimal
//     **/
//    private BigDecimal addFixedAmount(List<FixedInvestmentPlan> fixedInvestmentPlans){
//        BigDecimal planFixedAmount = BigDecimal.ZERO;
//        if (CollectionUtil.isNotEmpty(fixedInvestmentPlans)){
//            List<BigDecimal> bigDecimals = fixedInvestmentPlans.stream().map(FixedInvestmentPlan::getPlanTotalInvestment).filter(m -> Optional.ofNullable(m).isPresent()).collect(Collectors.toList());
//            planFixedAmount = BigDecimalUtil.addBigDecimals(bigDecimals);
//        }
//        return planFixedAmount;
//    }
//
//    /**
//     * @Author: Take-off
//     * @Description: 产权-总计划投资
//     * @Date: 3:54 PM 2023/2/13
//     * @Param: [stakeInvestmentPlans]
//     * @return: java.math.BigDecimal
//     **/
//    private BigDecimal addStakeAmount(List<StakeInvestmentPlan> stakeInvestmentPlans){
//        BigDecimal planFixedAmount = BigDecimal.ZERO;
//        if (CollectionUtil.isNotEmpty(stakeInvestmentPlans)){
//            List<BigDecimal> bigDecimals = stakeInvestmentPlans.stream().map(StakeInvestmentPlan::getPlanTotalInvestment).filter(m -> Optional.ofNullable(m).isPresent()).collect(Collectors.toList());
//            planFixedAmount = BigDecimalUtil.addBigDecimals(bigDecimals);
//        }
//        return planFixedAmount;
//    }
//
//}
